<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="templateadmin1.xhtml">
        <ui:define name="content">
                        <script type="text/javascript">
function formValidator(){

var price = document.getElementById("txtprice");
var capa = document.getElementById("txtcapacity");


// Check each input in the order that it appears in the form!


                if(isNumeric(price, "Please enter float")){
                        if(isNumeric(capa, "Please enter int")){

                                        return true;

                        }
                }


        return false;

}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
        return true;
}else{
        alert(helperMsg);
        elem.focus();
        return false;
}
}
function testPrice(form) {
var TestVar = form.elements["create:txtPr"];
var tax_id = parseFloat(TestVar.value);
if(isNaN(tax_id)){
alert ("You have input float");
return false;
}
return true;

}


function testCapaModel (form) {
var TestVar = form.elements["create:txtcapa"];
var tax_id = parseInt(TestVar.value);
if(isNaN(tax_id)){
alert ("You have input interger");
return false;
}
return true;

}
            </script>

            <h:form id ="create">
                <center>
                    <table border="0" cellpadding="0" cellspacing="0" id="detail-table" >

                        <tr><td>Model ID</td>
                            <td> <h:selectOneMenu value="#{carDetailBean.idModel}" styleClass="styledselect_form_hungtl">
                                    <f:selectItems value="#{carDetailBean.lmodel}" var="lm" itemLabel="#{lm.modelName}" itemValue="#{lm.modelID}"></f:selectItems>
                                </h:selectOneMenu></td>
                        </tr>
                        <tr>
                            <td>Car Name</td>
                            <td><h:inputText value="#{carDetailBean.car.carName}" id="txtcarn" required="true" requiredMessage="please input car name" styleClass="inp-form" ></h:inputText></td>
                            <h:message for="txtcarn"></h:message>
                        </tr>
                        <tr><td>Description</td>
                            <td><h:inputText value="#{carDetailBean.car.description}" id="txtdesc" required="true" requiredMessage="please input description name" styleClass="inp-form" ></h:inputText></td>
                       <h:message for="txtdesc"></h:message>
                        </tr>
                        <tr><td>Capacity</td>
                            <td><h:inputText value="#{carDetailBean.car.capacity}"  id="txtcapa" onblur="testCapaModel(this.form)" required="true" styleClass="inp-form"></h:inputText></td>
                        </tr>
                        <tr>
                            <td>Images</td>
                            <td><p:fileUpload widgetVar="uploader2" fileUploadListener="#{uploadbean.fileUpload2}" id="UploadPath" auto="true" ></p:fileUpload></td>
                        </tr>
                        <tr><td>Price</td>
                            <td><h:inputText value="#{carDetailBean.car.price}" id="txtPr" onblur="testPrice(this.form);"  required="true" styleClass="inp-form"></h:inputText></td>
                        </tr>
                        <tr><td><h:commandButton action="#{carDetailBean.actionCreateDetail}" value="Create" styleClass="form-submit"></h:commandButton></td>
                        </tr>
                    </table>
                </center>
            </h:form>
        </ui:define>
    </ui:composition>

</html>

